const mysql = require('../db/mysql57');

const powerDao = {
    // 鉴权接口 用于判断某个用户类型是否有某个权限
    checkPower(userTypeId, power) {
        let sql = `select * from UserTypePower where userTypeId = ? and powerId = (
                select id from Power where name = ?
            ) LIMIT 1`;
        let data = [ userTypeId, power ];
        return mysql.sqlExec(sql, data);
    },
    // 获取用户类型信息
    getUserType(userTypeId) {
        let sql = `select name from UserType where id = ? LIMIT 1`;
        let data = [ userTypeId ];
        return mysql.sqlExec(sql, data);
    },
    // 获取用户信息
    getUser(uid) {
        let sql = `select * from User where id = ? and isDel = ? and isEnable = ? LIMIT 1`;
        let data = [ uid, 'false', 'true' ];
        return mysql.sqlExec(sql, data);
    }
};

module.exports = powerDao;
